/**    
 * @Description: 博客园地址：https://www.cnblogs.com/zumengjie/      
 * @author: 顶风少年   
 * @date: 2021年4月9日 上午10:31:40
 */

package datang.dtdb.executor.statement;

import java.sql.Connection;
import java.sql.Statement;
import java.util.List;

import datang.dtdb.executor.Executor;
import datang.dtdb.executor.RowBounds;
import datang.dtdb.executor.parameter.ParameterHandler;
import datang.dtdb.executor.resultset.ResultSetHandler;
import datang.dtdb.mapping.BoundSql;
import datang.dtdb.mapping.MappedStatement;
import datang.dtdb.session.Configuration;
import datang.dtdb.session.ResultHandler;

/**
 * statement处理器抽象父类
 */
public abstract class BaseStatementHandler implements StatementHandler {

	protected final ResultSetHandler resultSetHandler;
	protected final ParameterHandler parameterHandler;
	protected final BoundSql boundSql;
	protected final Object parameter;
	protected final MappedStatement mappedStatement;
	protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameter,
			RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
		Configuration configuration = mappedStatement.getConfiguration();
		this.resultSetHandler = configuration.newResultSetHandler();
		this.parameterHandler = configuration.newParameterHandler(mappedStatement);
		this.boundSql = boundSql;
		this.parameter = parameter;
		this.mappedStatement = mappedStatement;
	}

	/**
	 * 从子类获取statement
	 * */
	@Override
	public Statement prepare(Connection connection) {
		Statement statement = null;
		statement = instantiateStatement(connection);
		return statement;
	}

	protected abstract Statement instantiateStatement(Connection connection);

}
